//
//  WMEInformationTableViewCell.m
//  everyDay_duiTang
//
//  Created by 恩叔 on 16/1/20.
//  Copyright © 2016年 enshu. All rights reserved.
//

#import "WMEInformationTableViewCell.h"
#import "WMEFirstPageModel.h"
#import <UIImageView+WebCache.h>
#import <UIButton+WebCache.h>
#import "PrefixHeader.pch"
#import <AFNetworking.h>
#import <Masonry.h>
#import "WMEUserBack.h"
#import "WMEUserViewController.h"
#import "WMEMoreViewController.h"

#pragma mark - 首页详情页tableView的cell
@interface WMEInformationTableViewCell ()<UIScrollViewDelegate>
@property (nonatomic, retain)UIImageView *img; /**< 图片 */
@property (nonatomic, retain)UILabel *title;/**< 文字 */
@property (nonatomic, retain)UIImageView *userPhoto; /**< 用户头像 */
@property (nonatomic, retain)UILabel *username; /**< 用户姓名 */
@property (nonatomic, retain)UILabel *usertitle; /**< 用户文字 */
@property (nonatomic, retain)UILabel *time; /**< 时间 */
@property (nonatomic, retain)UILabel *line; /**<分割线*/
@property (nonatomic, retain)UIView *back;/**<背景*/
@property (nonatomic, copy)NSString *width;/**<图片宽*/
@property (nonatomic, copy)NSString *height;/**<图片高*/
@property (nonatomic, retain)UILabel *zanCount;/**<赞的个数*/
@property (nonatomic, retain)NSMutableArray *zanArr;/**<存储赞的数组*/
@property (nonatomic, retain)NSMutableArray *pinglunArr;/**<存储评论的数组*/
@property (nonatomic, retain)UIView *pinglunView;/**<评论的背景视图*/
@property (nonatomic, retain)UILabel *pinglunCount;
@property (nonatomic, retain)NSMutableArray *plArr;
@property (nonatomic, retain)UIView *zanView;/**<赞的背景视图*/
@property (nonatomic, retain)UIScrollView *scrollView;
@property (nonatomic, assign)CGRect originalFrame;
@property (nonatomic, retain)UIImageView *lastImageView;

@end



@implementation WMEInformationTableViewCell

- (void)dealloc
{
    [_dic release];
    [_img release];
    [_title release];
    [_userPhoto release];
    [_username release];
    [_usertitle release];
    [_time release];
    [_line release];
    [_back release];
    [_width release];
    [_height release];
    [_zanCount release];
    [_zanArr release];
    [_zanView release];
    [_pinglunArr release];
    [_pinglunView release];
    [_pinglunCount release];
    [_lastImageView release];
    [_scrollView release];
    [_plArr release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //初始化 白色背景
        self.back = [[UIView alloc] init];
        _back.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_back];
        [_back release];
        
        //初始化 图片的尺寸
        self.img = [[UIImageView alloc] init];
        _img.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_img];
        _img.userInteractionEnabled = YES;
        UITapGestureRecognizer *imgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showZoomImageView:)];
        [_img addGestureRecognizer:imgTap];
        [_img release];
        
        //初始化 一条0.3分割线
        self.line = [[UILabel alloc] init];
        _line.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_line];
        [_line release];
        
        //初始化 文本框
        self.title = [[UILabel alloc] init];
//        _title.backgroundColor = [UIColor redColor];
        _title.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_title];
        [_title release];
        
        //初始化 用户头像
        self.userPhoto = [[UIImageView alloc] init];
//        _userPhoto.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_userPhoto];
        [_userPhoto release];
        
        //初始化 用户名字
        self.username = [[UILabel alloc] init];
//        _username.backgroundColor = [UIColor redColor];
        _username.font = [UIFont systemFontOfSize:15];
        _username.textColor = [UIColor colorWithRed:0 green:160/255.0 blue:233/255.0 alpha:1];
        [self.contentView addSubview:_username];
        [_username release];
        
        //初始化 图片所处的标题
        self.usertitle = [[UILabel alloc] init];
//        _usertitle.backgroundColor = [UIColor redColor];
        _usertitle.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_usertitle];
        [_usertitle release];
        
        //初始化 距今何时
        self.time = [[UILabel alloc] init];
//        _time.backgroundColor = [UIColor redColor];
        _time.font = [UIFont systemFontOfSize:10];
        _time.textColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_time];
        [_time release];
        
        //初始化 赞视图
        self.zanView = [[UIView alloc] init];
        _zanView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_zanView];
        [_zanView release];
        
        //初始化 赞的个数
        self.zanCount = [[UILabel alloc] init];
//        _zanCount.backgroundColor = [UIColor yellowColor];
        [self.zanView addSubview:_zanCount];
        [_zanCount release];
        //评论 视图的 初始化
        self.pinglunView = [[UIView alloc] init];
        _pinglunView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_pinglunView];
        [_pinglunView release];
        
        //评论的 个数 初始化
        self.pinglunCount = [[UILabel alloc]init];
        [self.pinglunView addSubview:_pinglunCount];
        [_pinglunCount release];
    }
    return self;
}
//重写set方法
- (void)setDic:(NSMutableDictionary *)dic{
    if (_dic != dic) {
        [_dic release];
        _dic = [dic retain];
        //计算 当前 屏宽下 对应的 高度
        self.width = _dic[@"photo"][@"width"];
        self.height = _dic[@"photo"][@"height"];
        
        //给img 赋图
        [_img sd_setImageWithURL:[NSURL URLWithString:[_dic[@"photo"][@"path"] stringByReplacingOccurrencesOfString:@"_webp" withString:@""]]];
        
        _title.text = _dic[@"msg"];
        
        [_userPhoto sd_setImageWithURL:[NSURL URLWithString:_dic[@"sender"][@"avatar"]]];
        _username.text = _dic[@"sender"][@"username"];
        _time.text = _dic[@"add_datetime_pretty"];
        _usertitle.text = [NSString stringWithFormat:@"收集到 %@", _dic[@"album"][@"name"]];
        _zanCount.text = [_dic[@"like_count"] stringValue];
        _pinglunCount.text = [_dic[@"reply_count"] stringValue];
        //临时变量数组
        NSArray *aaa = _dic[@"top_like_users"];
        //把数据 转成 MVC
        self.zanArr = [WMEFirstPageModel modelHandlerWithArray:aaa];
        
        NSArray *pl = _dic[@"top_comments"][@"object_list"];
        self.plArr = [WMEFirstPageModel modelHandlerWithArray:pl];
//        //遍历数组 对点赞的人 进行头像赋值
//        for (NSInteger i = 0; i < _zanArr.count; i++) {
//            WMEFirstPageModel *m = _zanArr[i];
//            if (i < 5) {
//                //不断调整视图位置
//                UIImageView *userImg = [[UIImageView alloc] initWithFrame:CGRectMake(i * ((WIDTH - 60) / 6 + 8) + 10, 60, (WIDTH - 180) / 6 , (WIDTH - 180)/ 6)];
//                [userImg sd_setImageWithURL:[NSURL URLWithString:m.avatar]];
//                userImg.layer.cornerRadius = (WIDTH / 6 - 30) / 2;
//                userImg.clipsToBounds = YES;
//                [self.zanView addSubview:userImg];
//                [userImg release];
//            }else if (i == 5)
//            {
//                UIButton *touxiang = [UIButton buttonWithType:UIButtonTypeSystem];
//                touxiang.frame = CGRectMake(i * ((WIDTH - 60)/ 6 + 8) + 10, 60, WIDTH / 6 - 30, WIDTH / 6 - 30);
//                [touxiang setBackgroundImage:[UIImage imageNamed:@"222"] forState:UIControlStateNormal];
//                [self.zanView addSubview:touxiang];
//            }else{
//                //我只需要5个视图添加在 view中 其他的全部不执行任何操作
//            }
//        }
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if (_dic) {
        //计算图片高
        
        CGFloat h = [[self class] heightWithImage:_width height:_height];
        _img.frame = CGRectMake(10, 10, WIDTH - 20, h);
//        [_img mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(ws.mas_left).with.offset(10);
//            make.top.equalTo(ws.mas_top).with.offset(10);
//            make.right.equalTo(ws.mas_right).with.offset(-10);
//            make.height.equalTo(@(h));
//        }];
        //设置 用户头像 的frame
        _userPhoto.frame = CGRectMake(20, h + 10 + 10, 40, 40);
//        [_userPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(ws.)
//        }]
        _userPhoto.userInteractionEnabled = YES;
        //头像 圆角设置
        _userPhoto.contentMode = UIViewContentModeScaleAspectFill;
        _userPhoto.layer.cornerRadius = _userPhoto.frame.size.width / 2;
        _userPhoto.clipsToBounds = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [_userPhoto addGestureRecognizer:tap];
        
        //用户名的 frame
        CGFloat textWidth = [[self class] widthWithText:_username.text];
        _username.frame = CGRectMake(20 + 30 + 15 , h + 10 + 10, textWidth, 20);
        
        //自适应宽度
        _time.frame = CGRectMake(20 + 30 + 10 + textWidth + 10, h + 10 + 10, 50, 20);
        
        //图片所处的标题
        _usertitle.frame = CGRectMake(20 + 30 + 15, h + 10 + 20 + 10, 200, 20);
        
        //线 ===================================这是分割线
        _line.frame = CGRectMake(20, _usertitle.frame.origin.y + 15 + 15, WIDTH - 30, 0.3);
    
        //正文! 计算高度 自适应高度
        CGFloat textHeight = [[self class] heightWithText:_title.text];
        _title.frame = CGRectMake(20, h + 20 + 40 + 20, WIDTH - 40, textHeight);
        _title.numberOfLines = 0;
        
        //通过计算完所有控件的高 布局背景的高度
        _back.frame = CGRectMake(10, 10, WIDTH - 20, h + textHeight + 80);
        //阴影的
        _back.layer.shadowOffset = CGSizeMake(0.1, 0.1);
        //阴影的不透明度
        _back.layer.shadowOpacity = 0.3;
        //阴影的半径
        _back.layer.shadowRadius = 1;

        //判断是否有 评论
        if ([_dic[@"top_comments"][@"object_list"] count]) {
//            NSLog(@"!~~!~!~!~!~%ld", [_dic[@"top_comments"][@"object_list"] count]);
            NSInteger muber = [_dic[@"reply_count"] integerValue];
            if (muber > 3) {
                muber = 4;
            }
            _pinglunView.frame = CGRectMake(10, _back.frame.size.height + 20, WIDTH - 20, 50 + 70 * muber);
            [self.contentView addSubview:_pinglunView];
            _pinglunView.layer.shadowOffset = CGSizeMake(0.1, 0.1);
            _pinglunView.layer.shadowOpacity = 0.3;
            _pinglunView.layer.shadowRadius = 1;
            UILabel *pinglun = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 40, 20)];
            pinglun.text = @"评论";
            pinglun.font = [UIFont systemFontOfSize:15];
            [self.pinglunView addSubview:pinglun];
            [pinglun release];
            //评论的个数
            _pinglunCount.frame = CGRectMake(50, 15, 100, 20);
            _pinglunCount.font = [UIFont systemFontOfSize:15];
            //大于3的 添加显示更多 的按钮
            if (muber > 3) {
                UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(10, _pinglunCount.frame.size.height + _pinglunCount.frame.origin.y + 15 + 70 * 3, WIDTH - 40, 0.3)];
                line.backgroundColor = [UIColor lightGrayColor];
                [_pinglunView addSubview:line];
                
                UIButton *more = [UIButton buttonWithType:UIButtonTypeSystem];
                more.frame = CGRectMake(10, _pinglunCount.frame.size.height + _pinglunCount.frame.origin.y + 30 + 3 * 70, WIDTH - 40, 40);
                [more setTitle:@"查看更多" forState:UIControlStateNormal];
                [more setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
                more.titleLabel.font = [UIFont systemFontOfSize:13];
                [self.pinglunView addSubview:more];
                [line release];
            }
            if (muber > 3) {
                muber = 3;
            }
            for (NSInteger i = 0; i < muber; i++) {
                UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(10, _pinglunCount.frame.size.height + _pinglunCount.frame.origin.y + 15 + 70 * i, WIDTH - 40, 0.3)];
                line.backgroundColor = [UIColor lightGrayColor];
                [_pinglunView addSubview:line];
                //每一个评论的视图 用来放置各种视图
                UIView *everyCommentView = [[UIView alloc] initWithFrame:CGRectMake(10, line.frame.origin.y + 5, WIDTH - 40, 60)];
//                everyCommentView.backgroundColor = [UIColor lightGrayColor];
                everyCommentView.userInteractionEnabled = YES;
                UITapGestureRecognizer *commentViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(commentTapAction:)];
                [everyCommentView addGestureRecognizer:commentViewTap];
                [self.pinglunView addSubview:everyCommentView];
                
                WMEFirstPageModel *model = _plArr[i];
                //发布评论的人 的头像
                UIImageView *plImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
                [everyCommentView addSubview:plImg];
                plImg.layer.cornerRadius = 20;
                plImg.contentMode = UIViewContentModeScaleAspectFill;
                plImg.clipsToBounds = YES;
                plImg.tag = i + 2300;
                plImg.userInteractionEnabled = YES;
                UITapGestureRecognizer *plImgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(plImgTapAction:)];
                [plImg addGestureRecognizer:plImgTap];
                [plImg sd_setImageWithURL:[NSURL URLWithString:model.avatar]];
                //发布评论的人 的名字
                UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(10 + 40 + 10, 10, WIDTH - 180 , 20)];
//                name.backgroundColor = [UIColor yellowColor];
                name.text = model.username;
                name.font = [UIFont boldSystemFontOfSize:13];
                [everyCommentView addSubview:name];
                //评论的内容
                UILabel *content = [[UILabel alloc] initWithFrame:CGRectMake(10 + 40 + 10, name.frame.size.height + name.frame.origin.y, WIDTH - 100, 20)];
//                content.backgroundColor = [UIColor redColor];
                if (model.recipientName.length != 0) {
                    content.text = [NSString stringWithFormat:@"回复 %@ : %@", model.recipientName, model.content];
                    content.font = [UIFont systemFontOfSize:13];
                    [everyCommentView addSubview:content];
                }else{
                    content.text = model.content;
                    content.font = [UIFont systemFontOfSize:13];
                    [everyCommentView addSubview:content];
                }
                //发布评论的时间
                UILabel *when = [[UILabel alloc] initWithFrame:CGRectMake(name.frame.size.width + name.frame.origin.x + 30, name.frame.origin.y, 60, 20)];
//                when.backgroundColor = [UIColor blueColor];
                when.font = [UIFont systemFontOfSize:11];
                when.textColor = [UIColor grayColor];
                when.text = model.add_datetime_pretty;
                [everyCommentView addSubview:when];
                [line release];
                [commentViewTap release];
                [plImg release];
                [name release];
                [content release];
                [when release];
            }
            //判断 [@"like_count"] 数组是不是有值
            if([_dic[@"like_count"] boolValue])
            {
                _zanView.frame = CGRectMake(10, _pinglunView.frame.origin.y + _pinglunView.frame.size.height + 10, WIDTH - 20, 110);
                [self like_countView];
            }else{
                _zanView.frame = CGRectMake(10, _pinglunView.frame.origin.y + _pinglunView.frame.size.height + 10, 0, 0);
            }
        }else{
            if ([_dic[@"like_count"] boolValue]) {
                _zanView.frame = CGRectMake(10, _back.frame.size.height + 20, WIDTH - 20, 110);
                [self like_countView];
            }else{
                _zanView.frame = CGRectMake(10 , _back.frame.size.height + 20, 0, 0);
            }
        }
        
        
    }
 
}
#pragma mark- 赞视图
- (void)like_countView
{
    //有人 赞 才显示 下列视图
    //赞模块的背景视图
//    _zanView.frame = CGRectMake(10, _pinglunView.frame.size.height + 20, WIDTH - 20, 110);
    //阴影的
    _zanView.layer.shadowOffset = CGSizeMake(0.1, 0.1);
    //阴影的不透明度
    _zanView.layer.shadowOpacity = 0.3;
    //阴影的半径
    _zanView.layer.shadowRadius = 1;
    
    
    //存放 赞 字 用的label
    UILabel *zan = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 20, 20)];
    zan.font = [UIFont systemFontOfSize:15];
    zan.text = @"赞";
    [self.zanView addSubview:zan];
    [zan release];
    
    //分割线 label
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, WIDTH - 40, 0.3)];
    label.backgroundColor = [UIColor lightGrayColor];
    [self.zanView addSubview:label];
    [label release];
    
    //显示 点赞 的 人数 label
    _zanCount.frame = CGRectMake(30, 15, 100, 20);
    _zanCount.font = [UIFont systemFontOfSize:15];
    //遍历数组 对点赞的人 进行头像赋值
    for (NSInteger i = 0; i < _zanArr.count; i++) {
        WMEFirstPageModel *m = _zanArr[i];
        if (i < 5) {
            //1-4显示 用户头像
            //不断调整视图位置
            UIImageView *userImg = [[UIImageView alloc] initWithFrame:CGRectMake(i * ((WIDTH - 90) / 6 + 10) + 10, 60, 40 , 40)];
            NSLog(@"%lf",userImg.frame.origin.x);
            //给视图赋值
            [userImg sd_setImageWithURL:[NSURL URLWithString:m.avatar]];
            //切圆角 取中间内容
            userImg.layer.cornerRadius = 40/ 2;
            userImg.contentMode = UIViewContentModeScaleAspectFill;
            userImg.clipsToBounds = YES;
            //打开用户交互
            userImg.userInteractionEnabled = YES;
            //tag
            userImg.tag = 1500 + i;
            //添加点击事件
            UITapGestureRecognizer *imgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgTapAction:)];
            //添加给图片
            [userImg addGestureRecognizer:imgTap];
            //添加视图
            [self.zanView addSubview:userImg];
            [imgTap release];
            [userImg release];
        }else if (i == 5) {
            //第5个显示 更多按钮 点击触发方法 查看所有点赞的人
            UIButton *touxiang = [UIButton buttonWithType:UIButtonTypeSystem];
            //位置
            touxiang.frame = CGRectMake(i * ((WIDTH - 90)/ 6 +10) + 10, 60, 40, 40);
            //给他添加图片
            [touxiang setBackgroundImage:[UIImage imageNamed:@"222"] forState:UIControlStateNormal];
            //添加事件
            [touxiang addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
            //添加进视图
            [self.zanView addSubview:touxiang];
        }else{
            //我只需要5个视图添加在 view中 其他的全部不执行任何操作
        }
    }
 
}
#pragma mark - 点击评论的人的头像触发的事件
- (void)plImgTapAction:(UITapGestureRecognizer *)tap
{
    WMEFirstPageModel *model = _plArr[tap.view.tag - 2300];
    NSString *userTemp = @"http://www.duitang.com/napi/people/profile/?__dtac=%257B%2522_r%2522%253A%2520%2522998121%2522%257D&_ts=1452865118.002704&app_code=gandalf&app_version=5.8%20rv%3A149591&device_name=iPhone%205&device_platform=iPhone5%2C2&include_fields=relationship%2Cbind_status%2Cinterests%2Cidentity%2Ccity%2Ccitycode%2Cgender%2Cbirthday%2Crecommend_info%2Cclub_count&locale=zh_CN&platform_name=iPhone%20OS&platform_version=9.2&screen_height=568&screen_width=320&user_id=11200118";
    NSString *userStr = [userTemp stringByReplacingOccurrencesOfString:@"11200118" withString:model.senderId.stringValue];
    //AFN网络请求
    AFHTTPSessionManager *userData = [AFHTTPSessionManager manager];
    [userData GET:userStr parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        nil;
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //        NSLog(@"%@", responseObject);
        NSMutableDictionary *dic = responseObject[@"data"];
        [self.delegate tiaotiaotiao:model.senderId.stringValue userDic:dic];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        nil;
    }];
}

#pragma mark - 评论视图的点击事件
- (void)commentTapAction:(UITapGestureRecognizer *)tap
{
    //判断是否登陆
    //登陆后点击可以回复此评论
}


#pragma mark - 赞的头像的点击事件
//图片的轻拍事件
- (void)imgTapAction:(UITapGestureRecognizer *)tap
{
//    NSLog(@"%ld", tap.view.tag);
    WMEFirstPageModel *model = _zanArr[tap.view.tag - 1500];
//    NSLog(@"%@", model.ID);
    //请求的是 wmeuserviewcontroller 的头部视图 wmeuserback 的数据 数据是字典
    NSString *userTemp = @"http://www.duitang.com/napi/people/profile/?__dtac=%257B%2522_r%2522%253A%2520%2522998121%2522%257D&_ts=1452865118.002704&app_code=gandalf&app_version=5.8%20rv%3A149591&device_name=iPhone%205&device_platform=iPhone5%2C2&include_fields=relationship%2Cbind_status%2Cinterests%2Cidentity%2Ccity%2Ccitycode%2Cgender%2Cbirthday%2Crecommend_info%2Cclub_count&locale=zh_CN&platform_name=iPhone%20OS&platform_version=9.2&screen_height=568&screen_width=320&user_id=11200118";
    NSString *userStr = [userTemp stringByReplacingOccurrencesOfString:@"11200118" withString:model.ID.stringValue];
//    NSLog(@"%@", userStr);
    //AFN网络请求
    AFHTTPSessionManager *userData = [AFHTTPSessionManager manager];
    [userData GET:userStr parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        nil;
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSLog(@"%@", responseObject);
        //头部视图的字典
        NSMutableDictionary *dic = responseObject[@"data"];
        //通过协议传给 VC 进行跳转
        //参数是 用户id 用户资料的dictionary
        [self.delegate tiaotiaotiao:model.ID.stringValue userDic:dic];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        nil;
    }];

    
}

#pragma mark -更多按钮触发的事件
- (void)moreAction:(UIButton *)btn
{
    [self.moDelagete tiaodDaoMore:_dic[@"id"] maxCount:_dic[@"like_count"]];
}



#pragma mark - 点击用户头像触发的事件
- (void)tapAction:(UITapGestureRecognizer *)tap
{
    NSString *str = [_dic[@"sender"][@"id"] stringValue];
    
    NSString *userTemp = @"http://www.duitang.com/napi/people/profile/?__dtac=%257B%2522_r%2522%253A%2520%2522998121%2522%257D&_ts=1452865118.002704&app_code=gandalf&app_version=5.8%20rv%3A149591&device_name=iPhone%205&device_platform=iPhone5%2C2&include_fields=relationship%2Cbind_status%2Cinterests%2Cidentity%2Ccity%2Ccitycode%2Cgender%2Cbirthday%2Crecommend_info%2Cclub_count&locale=zh_CN&platform_name=iPhone%20OS&platform_version=9.2&screen_height=568&screen_width=320&user_id=11200118";
    NSString *userStr = [userTemp stringByReplacingOccurrencesOfString:@"11200118" withString:str];
    //    NSLog(@"%@", userStr);
    //AFN网络请求
    AFHTTPSessionManager *userData = [AFHTTPSessionManager manager];
    [userData GET:userStr parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        nil;
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //        NSLog(@"%@", responseObject);
        NSMutableDictionary *dic = responseObject[@"data"];
        [self.delegate tiaotiaotiao:str userDic:dic];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        nil;
    }];
    

}

//计算图片的高 Image(h) / Image(w) = Photo(h) / Photo(w)
#pragma mark - 计算图片高
+ (CGFloat)heightWithImage:(NSString *)width height:(NSString *)height
{
    CGFloat h = (WIDTH - 20) * height.doubleValue / width.doubleValue;
    return h;
}

#pragma mark - 计算文本宽
+ (CGFloat)widthWithText:(NSString *)text
{
    //保存文本信息
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    //设置最大范围
    CGSize size = CGSizeMake(WIDTH - 100, 10);
    //算出文本需要的 rectangular
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    //返回文本 的 宽
    return rect.size.width;
}

#pragma mark - 计算文本高
+ (CGFloat) heightWithText :(NSString *)text
{
    //保存文本信息
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:13]};
    //最大范围
    CGSize size = CGSizeMake(WIDTH - 40, 1000);
    //计算 文本 需的rectangular
    CGRect r = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    //返回文本 的 高
    return r.size.height;
}
#pragma mark -点击图片放大
-(void)showZoomImageView:(UITapGestureRecognizer *)tap
{
    if (![(UIImageView *)tap.view image]) {
        return;
    }
    //scrollView作为背景
    UIScrollView *bgView = [[UIScrollView alloc] init];
    bgView.frame = [UIScreen mainScreen].bounds;
    bgView.backgroundColor = [UIColor blackColor];
    bgView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapBg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)];
    [bgView addGestureRecognizer:tapBg];
    
    UIImageView *picView = (UIImageView *)tap.view;
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = picView.image;
    imageView.frame = [bgView convertRect:picView.frame fromView:self];
    [bgView addSubview:imageView];
    
    [[[UIApplication sharedApplication] keyWindow] addSubview:bgView];
    
    self.lastImageView = imageView;
    self.originalFrame = imageView.frame;
    self.scrollView = bgView;
    //最大放大比例
    self.scrollView.maximumZoomScale = 1.5;
    self.scrollView.delegate = self;
    [UIView animateWithDuration:0.5 animations:^{
        CGRect frame = imageView.frame;
        frame.size.width = bgView.frame.size.width;
        frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
        frame.origin.x = 0;
        frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;
        imageView.frame = frame;
        if (frame.size.height > HEIGHT) {
            _scrollView.contentSize = CGSizeMake(frame.size.width, frame.size.height);
            frame.origin.x = 0;
            frame.origin.y = 0;
            imageView.frame = frame;
        }

    }];
    
}

-(void)tapBgView:(UITapGestureRecognizer *)tapBgRecognizer
{
    self.scrollView.contentOffset = CGPointZero;
    [UIView animateWithDuration:0.5 animations:^{
        self.lastImageView.frame = self.originalFrame;
        tapBgRecognizer.view.backgroundColor = [UIColor clearColor];
    } completion:^(BOOL finished) {
        [tapBgRecognizer.view removeFromSuperview];
        self.scrollView = nil;
        self.lastImageView = nil;
    }];
}



//返回可缩放的视图
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return scrollView.subviews.firstObject;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}




@end
